//guard.txt - Like patrolnpc, but it goes on path and, at end, returns to start. 
// There, it waits for a while before patrolling again.
//Cell 0 - Number of path to patrol. If 12 or over, stands still.
//Cell 1 - Number of state when talked to. Plays default text if left at 0.
//Cell 2 - Do text bubbles? If > 0, no.

begincreaturescript;

variables;

short i,target;
short talk_type;

body;

beginstate INIT_STATE;
	talk_type = get_ran(1,0,2);
	
	set_boss_level(ME,1);
	break;

beginstate DEAD_STATE;
break;

beginstate START_STATE; // going on patrol
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}

	if (get_foe_target(ME,6,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	//if ((get_attitude(ME) >= 10) && (dist_to_pc() <= 20)) {
		//set_foe_target(ME,pc_num());
		//set_state(3);
	//	}
		
	if (get_memory_cell(2) == 0) {
		if (talk_type == 0) {
			if (get_ran(1,0,100) < 4)
				create_text_bubble("Keep alert.");
				else if (get_ran(1,0,100) < 4)
					create_text_bubble("Keep watching.");	
				else if (get_ran(1,0,100) < 4)
					create_text_bubble("What was that?");	
			}
		if (talk_type == 1) {
			if (get_ran(1,0,100) < 4)
				create_text_bubble("Yawn.");
				else if (get_ran(1,0,100) < 4)
					create_text_bubble("Sigh.");
				else if (get_ran(1,0,100) < 4)
					create_text_bubble("Zzzzz.");
				else if (get_ran(1,0,100) < 2)
					create_text_bubble("I'm awake!");
			}
		if (talk_type == 2) {
			if (get_ran(1,0,100) < 4)
				create_text_bubble("Greetings.");
				else if (get_ran(1,0,100) < 4)
					create_text_bubble("Move along.");
				else if (get_ran(1,0,100) < 4)
					create_text_bubble("Keep moving.");
				else if (get_ran(1,0,100) < 4)
					create_text_bubble("Nothing to see here.");
			}

		}

	if (my_dist_from_start() >= 2) {
		if (get_ran(1,1,100) < 40) 
			return_to_start(ME,1);
		}
		else if ((get_ran(1,1,100) < 6) && (get_memory_cell(0) < 12)) {
			follow_path(ME,get_memory_cell(0),0);
			set_state(4);
			}

	if (am_i_doing_action() == FALSE)
		end_combat_turn();

break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate 4; // patrol
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	if (follow_path(ME,get_memory_cell(0),0) == TRUE)
		set_state(START_STATE);
break;

beginstate TALKING_STATE;
	if (get_memory_cell(1) == 0) {
		print_str("You try to start a conversation with the guard, but it pays no");
		print_str("  attention to you. The guard is serious about its duties.");
		}
		else begin_talk_mode(get_memory_cell(1));
break;